home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 November / Chip Kasım 2001.iso / prog / cdcode / smartsdk / setup.exe / stsdk.msi / SimpleTermRecognizer.cls_0001.C6DB95E3_9157_4174_9574_EF0371EC54EB < prev    next >
Encoding:
Visual Basic class definition  |  2001-04-13  |  3.5 KB  |  97 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "SmartTagRecognizer"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = True
  14. Option Explicit
  15.  
  16. Implements ISmartTagRecognizer
  17.  
  18. Dim terms(20) As String
  19. Dim numTerms As Integer
  20.  
  21. Private Sub Class_Initialize()
  22.     ' Declare these terms in all lowercase so that
  23.     ' case-insensitive searches can be performed.
  24.     terms(1) = "mocha latte"
  25.     terms(2) = "latte"
  26.     terms(3) = "carmelito"
  27.     terms(4) = "verona"
  28.     terms(5) = "columbia blend"
  29.     terms(6) = "antigua"
  30.     terms(7) = "kona"
  31.     terms(8) = "sunani"
  32.     terms(9) = "sumatra"
  33.     terms(10) = "espresso"
  34.     terms(11) = "java"
  35.     numTerms = 11
  36.  End Sub
  37.  
  38. Private Property Get ISmartTagRecognizer_ProgId() As String
  39.     ' Create a unique identifier for this recognizer
  40.     ' that corresponds to the ProgID of this dll.
  41.  
  42. ISmartTagRecognizer_ProgId = "SimpleTerm.SmartTagRecognizer "
  43. End Property
  44.  
  45. Private Property Get ISmartTagRecognizer_Name(ByVal LocaleID As Long) As String
  46.     ' Add a short phrase that describes this recognizer that will be
  47.     ' shown in the Tools>Autocorrect Option>Smart Tags
  48.     ' dialog box in both Word and Excel.
  49.     ISmartTagRecognizer_Name = "My Simple Term Recognizer"
  50. End Property
  51.  
  52. Private Property Get ISmartTagRecognizer_Desc(ByVal LocaleID As Long) As String
  53.     ' Create a longer description of this recognizer.
  54.     ISmartTagRecognizer_Desc = "Simple Term Recognizer recognizes Fourth Coffee flavors in documents"
  55. End Property
  56.  
  57. Private Property Get ISmartTagRecognizer_SmartTagCount() As Long
  58.     ' Specify the number of smart tag types this recognizer supports.
  59.     ' 1 in this case.
  60.     ISmartTagRecognizer_SmartTagCount = 1
  61. End Property
  62.  
  63. Private Property Get ISmartTagRecognizer_SmartTagName(ByVal SmartTagID As Long) As String
  64.     ' Provide the name of the smart tag type supported.
  65.     ' SmartTag names are always in the format of
  66.     ' namespaceURI#tagname.
  67.     If (SmartTagID = 1) Then
  68.         ISmartTagRecognizer_SmartTagName = "schemas-fourth-com/fourthcoffee#flavor"
  69.     End If
  70. End Property
  71.  
  72. Private Property Get ISmartTagRecognizer_SmartTagDownloadURL(ByVal SmartTagID As Long) As String
  73.     ' For this particular smart tag type, there is no website
  74.     ' to support a smart tag download URL, so return nothing.
  75.     ISmartTagRecognizer_SmartTagDownloadURL = ""
  76. End Property
  77.  
  78. Public Sub ISmartTagRecognizer_Recognize(ByVal Text As String, ByVal DataType As SmartTagLib.IF_TYPE, ByVal LocaleID As Long, ByVal RecognizerSite As SmartTagLib.ISmartTagRecognizerSite)
  79.     Dim i As Integer
  80.     Dim index As Integer, termlen As Integer
  81.     Dim propbag As SmartTagLib.ISmartTagProperties
  82.     Text = LCase(Text)
  83.     For i = 1 To numTerms
  84.         index = InStr(Text, terms(i))
  85.         termlen = Len(terms(i))
  86.         While (index > 0)
  87.             ' Ask the recognizer site for a property bag
  88.             Set propbag = RecognizerSite.GetNewPropertyBag
  89.             ' Commit the smart tag to the application
  90.             RecognizerSite.CommitSmartTag "schemas-fourth-com/fourthcoffee#flavor", index, termlen, propbag
  91.             ' Look for another smart tag in the string
  92.             index = InStr(index + termlen, Text, terms(i))
  93.         Wend
  94.     Next i
  95. End Sub
  96.  
  97.